<template>
  vue-draggable-plus 拖拽组件测试
  <div class="flex" style="display: flex; justify-content: space-around">
    <VueDraggable
      class="item"
      v-model="list1"
      :animation="150"
      ghostClass="ghost"
      group="people"
      @update="onUpdate"
      @add="onAdd(1)"
      @remove="remove"
    >
      <div v-for="item in list1" :key="item.id" class="itemChild">
        {{ item.name }}
      </div>
    </VueDraggable>
    <VueDraggable
      class="item"
      v-model="list2"
      :animation="150"
      group="people"
      ghostClass="ghost"
      @update="onUpdate"
      @add="onAdd(2)"
      @remove="remove"
    >
      <div v-for="item in list2" :key="item.id" class="itemChild">
        {{ item.name }}
      </div>
    </VueDraggable>
  </div>
  <div class="flex justify-between">
    <preview-list :list="list1" />
    <preview-list :list="list2" />
  </div>
</template>

<script lang="ts" setup>
import { ref } from 'vue'
import { VueDraggable } from 'vue-draggable-plus'
const list1 = ref([
  {
    name: 'Joao',
    id: '1',
  },
  {
    name: 'Jean',
    id: '2',
  },
  {
    name: 'Johanna',
    id: '3',
  },
  {
    name: 'Juan',
    id: '4',
  },
])
const list2 = ref(
  list1.value.map((item) => ({
    name: `${item.name}-2`,
    id: `${item.id}-2`,
  })),
)
function onUpdate() {
  console.log('update')
}
function onAdd(num: number) {
  console.log(num + 'add')
}
function remove() {
  console.log('remove')
}
</script>

<style scoped>
.item {
  width: 200px;
  border: 1px solid black;
}

.item > .itemChild {
  padding: 20px;
  background-color: white;
  border: 1px solid yellow;
}
</style>
